import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-09-28
 * Time: 13:00
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int[] arr = new int[a];
        for(int i = 0;i < a;i++)arr[i] = in.nextInt();
        Arrays.sort(arr);
        HashSet<Integer> set = new HashSet<>();
        int ret = 0,left = 0,right = 0,count = 0;
        while(right < a){
            if(set.contains(arr[right])){
                count++;
                right++;
                continue;
            }
            else set.add(arr[right]);
            if(arr[right] - arr[left] > b){
                if(set.contains(arr[left])){
                    set.remove(arr[left]);
                    count--;
                }
                left++;
            }
            if(arr[right] - arr[left] <= b){
                ret += right - left - count;
            }
            right++;
        }
        System.out.println(ret);
    }
    public static void main645(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        for (int i = 0; i < a; i++) {
            boolean flag = false;
            for (int j = 0; j < 2; j++) {
                long b = in.nextLong();
                for (int k = 2; k <= Math.sqrt(b); k++) {
                    if (flag) break;
                    if (j % k == 0) {
                        flag = true;
                        break;
                    }
                }
            }
            System.out.println(flag ? "YES" : "NO");
        }
    }
}
